﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Gollie.Controls.Admin
{
	public partial class ViewMail : AdminRequiredBaseUserControl
	{
		protected void Page_Load(object sender, EventArgs e)
		{

		}

		protected override void OnFirstHit(object sender, EventArgs e)
		{
			this.tbFrom.Text = DateTime.Today.ToString("dd-MM-yyyy , HH:mm");
			this.tbTo.Text = DateTime.Today.AddDays(1).ToString("dd-MM-yyyy , HH:mm");

			this.Refresh();
		}

		protected override void OnPostBack(object sender, EventArgs e)
		{
			this.Refresh();
		}

		private void Refresh()
		{
			DateTime from;
			DateTime to;

			bool ok1 = DateTime.TryParse(this.tbFrom.Text, out from);
			bool ok2 = DateTime.TryParse(this.tbTo.Text, out to);
			bool ok = ok1 && ok2;

			if (!ok)
			{
				if (!ok1) this.tbFrom.BackColor = System.Drawing.Color.Red;
				else this.tbFrom.BackColor = System.Drawing.Color.White;

				if (!ok2) this.tbTo.BackColor = System.Drawing.Color.Red;
				else this.tbTo.BackColor = System.Drawing.Color.White;
			}

			if (ok)
			{
				DataTables.MailsSent mailsSent = new DataTables.MailsSent(from, to);
				this.GridView1.DataSource = mailsSent;
				this.GridView1.DataBind();

			}
		}
	}
}